package com.example.yuejian.yuejian.model;

import com.example.yuejian.yuejian.base.ModleListener;
import com.example.yuejian.yuejian.bean.Collection;
import com.example.yuejian.yuejian.bean.IsFollow;
import com.example.yuejian.yuejian.service.CollectService;

import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;
import retrofit2.Retrofit;
import retrofit2.converter.gson.GsonConverterFactory;

/**
 * Created by Administrator on 2017/9/18.
 */

public class CollectionModel {
    private Retrofit retrofit;
    public CollectionModel(){
        retrofit=new Retrofit.Builder()
                .addConverterFactory(GsonConverterFactory.create())
                .baseUrl(Contants.BASE_URL)
                .build();

    }

    //
    public void followMaster(int user_id, int type_id, int collection_id, final ModleListener modleListener){
       CollectService service=retrofit.create(CollectService.class);
        Call<Collection>call=service.followmaster(user_id,type_id,collection_id);
       call.enqueue(new Callback<Collection>() {
           @Override
           public void onResponse(Call<Collection> call, Response<Collection> response) {
               if (response.isSuccessful() && response.body() != null) {
                   modleListener.onResponse(response.body());
               } else
                   modleListener.onFail("onresponse fail");
           }

           @Override
           public void onFailure(Call<Collection> call, Throwable t) {
               modleListener.onFail(t.toString());
           }
       });
    }
    //是否关注
    public void isfollow(String user_id,int type_id,int collection_id,final ModleListener modleListener){
        CollectService service=retrofit.create(CollectService.class);
       Call <IsFollow>call =service.isFollow(user_id,type_id,collection_id);
        call.enqueue(new Callback<IsFollow>() {
            @Override
            public void onResponse(Call<IsFollow> call, Response<IsFollow> response) {
                if (response.isSuccessful() && response.body() != null) {
                    modleListener.onResponse(response.body());
                } else
                    modleListener.onFail("onresponse fail");
            }

            @Override
            public void onFailure(Call<IsFollow> call, Throwable t) {
                modleListener.onFail(t.toString());
            }
        });
    }
    public  Call CancelMyfollow(int user_id, int type_id, int collection_id)
    {
        CollectService service=retrofit.create(CollectService.class);
        return  service.followmaster(user_id,type_id,collection_id);

    }

}
